<?php
function parent_cmp($a, $b)
{
	if ($a ['pid'] == $b ['pid'])
		return 0;
	return ($a ['pid'] > $b ['pid']) ? 1 : - 1;
}
function parse($array)
{
	$tree = array ();
	$index = array ();
	$deep = 0;
	uasort ( $array, 'parent_cmp' );
	foreach ($array as $k=>$v){
		if($v['pid']==0){			
			$v['deep']=0;
			$key=$v['id'];
			$tree[$key]=$v;
		}else {
			$v['deep']=0;
			$key=$v['id'];
			$tree[$key]=$v;	
		}		
	}
	return $array;
}
?>